<template>
  <el-dialog
    v-model="dialogVisible"
    :width="width"
    :before-close="handleClose"
    :show-close="false"
    :close-on-click-modal="closeOnClickModal"
    :close-on-press-escape="closeOnPressEscape"
    :top="top"
    :center="center"
    :destroy-on-close="destroyOnClose"
    :class="customClass"
  >
    <template #header="{close}">
         <div class="header-title">{{title}}</div>
         <div class="close-icon" @click="handleCloseClick(close)">
          <img src="@/assets/imgs/home/close.png" class="w-30px h-30px" alt="">
        </div>
    </template>
    <div class="dialog-content">
      <slot name="content"></slot>
    </div>
    <div class="dialog-footer">
      <slot name="footer"></slot>
    </div>
  </el-dialog>
</template>
    
<script lang="ts">
import { defineComponent } from "vue";
export default defineComponent({
  name: "MDialog",
});
</script>
<script setup lang="ts">
const emit = defineEmits<{
  (e: 'update:dialogVisible', value: boolean): void
  (e: 'close'): void
}>()

const props = withDefaults(defineProps<{
  title: string
  width?: string
  closeOnClickModal?: boolean
  closeOnPressEscape?: boolean
  top?: string
  center?: boolean
  destroyOnClose?: boolean
  customClass?: string
}>(), {
  width: '30%',
  closeOnClickModal: false,
  closeOnPressEscape: true,
  top: '15vh',
  center: false,
  destroyOnClose: false,
  customClass: ''
})
const dialogVisible = defineModel<boolean>('dialogVisible')
// 处理关闭事件
const handleClose = (done: () => void) => {
  emit('close')
  done()
}
// 处理点击关闭按钮事件
const handleCloseClick = (close: () => void) => {
  emit('close')
  close()
}
</script>
<style lang="scss" scoped>
:deep(.el-dialog) {
  border-radius: 8px;
  overflow: hidden;
  .el-dialog__header {
    margin: 0;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #f0f0f0;
  }
  .el-dialog__body {
    padding: 0px;
  }
}

.header-title {
  font-size: 16px;
  font-weight: 600;
  color: #ffffff;
}
.close-icon {
  cursor: pointer;
  transition: transform 0.2s;
  &:hover {
    transform: scale(1.1);
  }
}
.dialog-content {
  max-height: 70vh;
  overflow-y: auto;
  padding:  20px 20px 0 20px;
  
  &::-webkit-scrollbar {
    width: 3px;
  }
  &::-webkit-scrollbar-thumb {
    background-color: #04609e;
  }
}
.dialog-footer {
  display: flex;
  justify-content: flex-end;
  padding: 10px;
  width: 100%;
}


</style>